package com.garen.fire.dao.impl;

import com.garen.fire.dao.IFireDutyDao;
import com.garen.fire.entity.FireDuty;
import com.garen.utils.MapBuilder;
import com.garen.common.BaseDao;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.PostConstruct;


@Repository
public class FireDutyDaoImpl extends BaseDao<FireDuty> implements IFireDutyDao {

	@PostConstruct
	private void init(){
		initOrm(FireDuty.class);
	}

	/*
	* 查询中队排班表
	*/
	@Override
	public List<FireDuty> getFireDutyList(String orgId,Date kssj,Date jssj){
		String sql = "select d.duty_id,d.fire_car,u.user_id as fire_man,u.user_name as fire_man_name,"
				+ " (year(now())-year(u.user_birthday)-1) + ( DATE_FORMAT(u.user_birthday, '%m%d') <= DATE_FORMAT(NOW(), '%m%d') ) as fire_man_age ,"
				+ " (select code_name from fire_code t1 where t1.code_type = '5' and code_value=u.user_police_rank) as fire_police_rank "
					+ " from fire_user u left join fire_duty d on  d.fire_man = u.user_id"
					+ " and d.fire_date between :kssj and :jssj "
					+ " where u.user_org_id = :orgId ";
		 Map<String,Object> paramMap = new MapBuilder()
				 .put("orgId", orgId)
				  .put("kssj", kssj)
				  .put("jssj", jssj)
				 .build();
		return getListBySQL(sql, paramMap);
	}
	
	
}
